home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 6 / develop 6 code / TCP / NewsWatcher / NewsWatcher 2.0d15 source / source / collapse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-30  |  6.2 KB  |  220 lines  |  [TEXT/KAHL]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     collapse.c
  4.  
  5.     This module handles collapsing and expanding threads.
  6.     
  7.     Portions copyright © 1990, Apple Computer.
  8.     Portions copyright © 1993, Northwestern University.
  9.  
  10. ----------------------------------------------------------------------------*/
  11.  
  12. #include "glob.h"
  13. #include "collapse.h"
  14. #include "draw.h"
  15. #include "menus.h"
  16. #include "resize.h"
  17. #include "util.h"
  18. #include "wind.h"
  19.  
  20.  
  21. /*    ExpandCollapseThread expands or collapses a single thread.
  22.  
  23.     Entry:    wind = pointer to window record.
  24.             theCell = any cell in the thread to be expanded or collapsed.
  25. */
  26.  
  27. static void ExpandCollapseThread (WindowPtr wind, Cell theCell)
  28. {
  29.     TWindow **info;
  30.     ListHandle theList;
  31.     TSubject **subjectArray, theSubject;
  32.     Cell tmpCell, newCell;
  33.     long finalTicks;
  34.     short i, nextInThread, cellDataLen, cellData;
  35.     ControlHandle scrollBar;
  36.     Rect inval;
  37.     
  38.     info = (TWindow**)GetWRefCon(wind);
  39.     theList = (**info).theList;
  40.     subjectArray = (**info).subjectArray;
  41.     cellDataLen = 2;
  42.     LGetCell(&cellData, &cellDataLen, theCell, theList);
  43.     theSubject = (*subjectArray)[cellData];
  44.     if (theSubject.threadOrdinal != 1) {
  45.         theCell.v -= theSubject.threadOrdinal-1;
  46.         LGetCell(&cellData, &cellDataLen, theCell, theList);
  47.         theSubject = (*subjectArray)[cellData];
  48.     }
  49.     theSubject.collapsed = !theSubject.collapsed;
  50.     nextInThread = cellData;
  51.     for (i = 0; i < theSubject.threadLength; i++) {
  52.         (*subjectArray)[nextInThread].collapsed = theSubject.collapsed;
  53.         nextInThread = (*subjectArray)[nextInThread].nextInThread;
  54.     }
  55.     (*subjectArray)[cellData].onlyRedrawTriangle = true;
  56.     (*subjectArray)[cellData].onlyRedrawCheck = false;
  57.     (*subjectArray)[cellData].drawTriangleFilled = true;
  58.     LDraw(theCell, theList);
  59.     (*subjectArray)[cellData].onlyRedrawTriangle = false;
  60.     (*subjectArray)[cellData].onlyRedrawCheck = true;
  61.     LDraw(theCell, theList);
  62.     (*subjectArray)[cellData].onlyRedrawTriangle = true;
  63.     (*subjectArray)[cellData].onlyRedrawCheck = false;
  64.     
  65.     if (theSubject.collapsed) {
  66.         LDelRow(theSubject.threadLength-1, theCell.v+1, theList);
  67.         SetPt(&tmpCell, 0, 0);
  68.         if (!LGetSelect(true, &tmpCell, theList)) 
  69.             LSetSelect(true, theCell, theList);
  70.     } else {
  71.         LDoDraw(false, theList);
  72.         LAddRow(theSubject.threadLength-1, theCell.v+1, theList);
  73.         newCell = theCell;
  74.         nextInThread = theSubject.nextInThread;
  75.         for (i = 1; i < theSubject.threadLength; i++) {
  76.             newCell.v++;
  77.             LSetCell(&nextInThread, 2, newCell, theList);
  78.             nextInThread = (*subjectArray)[nextInThread].nextInThread;
  79.         }
  80.         LDoDraw(true, theList);
  81.         inval = wind->portRect;
  82.         inval.top = (theCell.v - (**theList).visible.top + 1) *
  83.             (**theList).cellSize.v;
  84.         inval.right -= 15;
  85.         inval.bottom -= 15;
  86.         InvalRect(&inval);
  87.         HandleUpdate(wind);
  88.     }
  89.     
  90.     Delay(8, &finalTicks);
  91.     (*subjectArray)[cellData].drawTriangleFilled = false;
  92.     LDraw(theCell, theList);
  93.     (*subjectArray)[cellData].onlyRedrawTriangle = false;
  94.     scrollBar = ((WindowPeek)wind)->controlList;
  95.     SetWindowNeedsZooming(wind);
  96. }
  97.  
  98.  
  99. /*    DoExpandCollapseSelectedThread expands or collapses just the currently 
  100.     selected thread in a subject window.
  101.     
  102.     Entry:    wind = pointer to subject window. 
  103. */
  104.     
  105. void DoExpandCollapseSelectedThread (WindowPtr wind)
  106. {
  107.     TWindow **info;
  108.     ListHandle theList;
  109.     TSubject **subjectArray;
  110.     Cell theCell, tmpCell;
  111.     short cellDataLen, cellData;
  112.     TSubject theSubject;
  113.  
  114.     SetPort(wind);
  115.     info = (TWindow**)GetWRefCon(wind);
  116.     theList = (**info).theList;
  117.     subjectArray = (**info).subjectArray;
  118.     SetPt(&theCell, 0, 0);
  119.     if (!LGetSelect(true, &theCell, theList)) return;
  120.     tmpCell = theCell;
  121.     tmpCell.v++;
  122.     if (LGetSelect(true, &tmpCell, theList)) return;
  123.     cellDataLen = 2;
  124.     LGetCell(&cellData, &cellDataLen, theCell, theList);
  125.     theSubject = (*subjectArray)[cellData];
  126.     if (theSubject.threadLength <= 1) return;
  127.     ExpandCollapseThread(wind, theCell);
  128. }
  129.  
  130.  
  131. /*    TriangleClick handles mouse-downs on the expand/collapse triangle
  132.     thread controls in subject windows.
  133.     
  134.     Entry:    wind = pointer to subject window.
  135.             where = location of mouse down in local coordinates.
  136. */
  137.  
  138. Boolean TriangleClick (WindowPtr wind, Point where)
  139. {
  140.     TWindow **info;
  141.     ListHandle theList;
  142.     TSubject **subjectArray, theSubject;
  143.     FontInfo fontInfo;
  144.     Cell theCell;
  145.     short cellData, cellDataLen;
  146.     Rect hitRect;
  147.     Boolean inHitRect, newInHitRect;
  148.     short visTop, cellHeight;
  149.  
  150.     info = (TWindow**)GetWRefCon(wind);
  151.     theList = (**info).theList;
  152.     visTop = (**theList).visible.top;
  153.     cellHeight = (**theList).cellSize.v;
  154.     subjectArray = (**info).subjectArray;
  155.     GetFontInfo(&fontInfo);
  156.     SetRect(&hitRect, 0, 0, (**theList).indent.h + fontInfo.ascent, 0);
  157.     if (where.h > hitRect.right) return false;
  158.     theCell.h = 0;
  159.     theCell.v = where.v/cellHeight + visTop;
  160.     if (theCell.v >= (**theList).dataBounds.bottom) return false;
  161.     cellDataLen = 2;
  162.     LGetCell(&cellData, &cellDataLen, theCell, theList);
  163.     theSubject = (*subjectArray)[cellData];
  164.     if (theSubject.threadLength == 1 || theSubject.threadOrdinal > 1) 
  165.         return false;
  166.     (*subjectArray)[cellData].drawTriangleFilled = inHitRect =  true;
  167.     (*subjectArray)[cellData].onlyRedrawTriangle = true;
  168.     LDraw(theCell, theList);
  169.     hitRect.top = (theCell.v - visTop) * cellHeight;
  170.     hitRect.bottom = hitRect.top + cellHeight;
  171.     while (StillDown()) {
  172.         GetMouse(&where);
  173.         newInHitRect = PtInRect(where, &hitRect);
  174.         if (newInHitRect != inHitRect) {
  175.             (*subjectArray)[cellData].drawTriangleFilled = newInHitRect;
  176.             LDraw(theCell, theList);
  177.             inHitRect = newInHitRect;
  178.         }
  179.     }
  180.     if (!inHitRect) {
  181.         (*subjectArray)[cellData].drawTriangleFilled = false;
  182.         (*subjectArray)[cellData].onlyRedrawTriangle = false;
  183.         return true;
  184.     }
  185.     ExpandCollapseThread(wind, theCell);
  186.     return true;
  187. }
  188.  
  189. void ExpandCollapseKey (WindowPtr wind, char theChar)
  190. {
  191.     TWindow **info;
  192.     ListHandle theList;
  193.     TSubject **subjectArray;
  194.     Cell theCell;
  195.     short cellDataLen, cellData;
  196.     TSubject theSubject;
  197.  
  198.     SetPort(wind);
  199.     info = (TWindow**)GetWRefCon(wind);
  200.     theList = (**info).theList;
  201.     subjectArray = (**info).subjectArray;
  202.  
  203.     SetPt(&theCell, 0, 0);
  204.     while (true) {
  205.         if (!LGetSelect(true, &theCell, theList)) break;
  206.         cellDataLen = 2;
  207.         LGetCell(&cellData, &cellDataLen, theCell, theList);
  208.         theSubject = (*subjectArray)[cellData];
  209.         if (theSubject.threadLength > 1)
  210.             if (theSubject.collapsed && theChar == rightArrow ||
  211.                 !theSubject.collapsed && theChar == leftArrow) 
  212.                     ExpandCollapseThread(wind, theCell);
  213.         theCell.v++;
  214.     }
  215. }
  216.  
  217.  
  218.  
  219.  
  220.